package com.tmc.platform.ctrip.util;

import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver;
import com.tmc.platform.ctrip.bean.BaggagesAndMealInfo;
import com.tmc.platform.ctrip.bean.IssueBillDetailInfo;
import com.tmc.platform.ctrip.bean.OpenIssueBillDetailResponse;
import com.tmc.platform.ctrip.bean.OpenIssueBillInfoResponse;
import com.tmc.platform.ctrip.bean.OpenIssueBillResponse;
import com.tmc.platform.ctrip.bean.OpenIssueOrderListResponse;
import com.tmc.platform.ctrip.bean.OpenSearchIssueBillResponse;

public class XStreamUtil {

	private static XStream respXStream = null;
	private static XStream reqXStream = null;
	
	public static XStream getRespXStream(){
		if (respXStream == null){
			respXStream = new XStream(new DomDriver());
			respXStream.autodetectAnnotations(true); 
			respXStream.alias("OpenIssueOrderListResponse", OpenIssueOrderListResponse.class);
			respXStream.alias("OpenIssueBillResponse", OpenIssueBillResponse.class);
			respXStream.alias("OpenIssueBillDetailResponse", OpenIssueBillDetailResponse.class);
			respXStream.alias("OpenIssueBillInfoResponse", OpenIssueBillInfoResponse.class);
			respXStream.alias("IssueBillDetailInfo", IssueBillDetailInfo.class);
			respXStream.alias("BaggagesAndMealInfo",BaggagesAndMealInfo.class);
			respXStream.alias("OpenSearchIssueBillResponse",OpenSearchIssueBillResponse.class);
		}
		return respXStream;
	}
	
	public static XStream getReqXStream(){
		if (reqXStream == null){
			reqXStream = new XStream(new DomDriver());
			respXStream.autodetectAnnotations(true); 
		}
		return reqXStream;
	}
	
	@SuppressWarnings("unchecked")
	public static <T> T fromXml(String xml){
		return (T) getRespXStream().fromXML(xml);
	}
	
	public static String toXml(Object obj){
		return getReqXStream().toXML(obj);
	}
}
